﻿namespace CodeContrib
{
	public class RandomUrl : IRandom<string>
	{
		private static readonly string[] _protocols;
		private readonly RandomCompanyName _randomCompanyName;
		private readonly RandomItem<string> _randomProtocol;
		private readonly RandomTopLevelDomain _randomTopLevelDomain;

		static RandomUrl()
		{
			_protocols = new[]
				             {
					             "http://", "https://",
				             };
		}

		public RandomUrl()
		{
			_randomCompanyName = new RandomCompanyName();
			_randomProtocol = new RandomItem<string>(_protocols);
			_randomTopLevelDomain = new RandomTopLevelDomain();
		}

		public string Next()
		{
			var protocol = _randomProtocol.Next();
			var companyName = _randomCompanyName.Next().Replace(" ", string.Empty).Replace(".", string.Empty).Replace(",", string.Empty);
			var topLevelDomain = _randomTopLevelDomain.Next();

			return string.Format("{0}www.{1}.{2}", protocol, companyName, topLevelDomain).ToLower();
		}
	}
}